<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dung
 * Date: 2/19/14
 * Time: 12:07 AM
 * To change this template use File | Settings | File Templates.
 */
?>
<?php
if(isset($_SESSION["users_id"]) && $_SESSION["group_id"]==1){
    $id=$_GET['employee_id'];
    $employee=EmployeeDetail($id);
    $row_employee=mysql_fetch_array($employee);
    if(isset($_POST["btnEdit"]))
    {
        $name=$_POST["name"];
        $image=$_POST["Image"];
        $detail=$_POST["Content"];
        $language_id=$_POST["language"];settype($language_id,"int");
        EditEmployee($id,$name,$image,$detail,$language_id);
        header("location:index.php?p=employeelist");
    }
    ?>
    <form id="maincp" name="form1" method="post" action="">
        <h1 class="h1">Add Employee</h1>
        <p>Please complete all form below to add a new article.</p>
        <ul class="list2">
            <li><h3>Name</h3></li>
            <li><input value="<?php echo $row_employee['name'] ?>" class="input" type="text" name="name" id="name" /></li>
            <li><h3>Avatar</h3></li>
            <li><img src="<?php echo $row_employee['image'] ?>" style="width: 150px;height: 150px" class="input twocol" type="text" name="Image" id="Image" /><br/>
                <input value="<?php echo $row_employee['image'] ?>" class="input twocol" type="text" name="Image" id="Image" />
                <input class="twocol2" onclick="BrowseServer('','Image')" type="button" name="btnChonFile" id="btnChonFile" value="Browse" />
            </li>
            <li><h3>Info</h3></li>
            <li><textarea class="ckeditor" name="Content" id="Content" cols="45" rows="5"><?php echo $row_employee['detail']; ?></textarea></li>
            <li>
                <fieldset>
                    <legend><h3>Language</h3></legend>
                    <p>Choose contents language.</p>
                    <select id="language" name="language" style="width: 100px">
                        <?php
                        $language=LanguageList();
                        while($row_language=mysql_fetch_array($language)){ ?>
                            <?php if($row_employee['language_id']==$row_language['language_id']){ ?>
                            <option selected="selected" value="<?php echo $row_language['language_id']; ?>"><?php echo $row_language['name']; ?></option>
                            <?php } else { ?>
                            <option value="<?php echo $row_language['language_id']; ?>"><?php echo $row_language['name']; ?></option>
                            <?php } ?>
                        <?php } ?>
                    </select>
                </fieldset>
            </li>
            <li><input class="button addnews" type="submit" name="btnEdit" id="btnEdit" value="Edit Employee" /></li>
        </ul>
        <a href="index.php?p=cpanel" title="Back to Dashboard">&laquo; Back to Dashboard.</a>
    </form>

    <script type="text/javascript">
        function BrowseServer(startupPath, functionData) {
            var finder = new CKFinder();
            finder.basePath = 'js/ckfinder/';
            finder.startupPath = startupPath;
            finder.selectActionFunction = SetFileField; 
            finder.selectActionData = functionData;
            finder.popup();
        }//BrowseServer

        function SetFileField(fileUrl, data) {
            document.getElementById(data["selectActionData"]).value = fileUrl;
        }

        function ShowThumbnails(fileUrl, data) {
            var sFileName = this.getSelectedFile().name;
            // this = CKFinderAPI
            document.getElementById('thumbnails').innerHTML += '<div class="thumb">' + '<img src="' + fileUrl + '" />' + '<div class="caption">' + '<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' + '</div>' + '</div>';
            document.getElementById('preview').style.display = "";
            return false;
        }
    </script>

<?php
}else{
    header("location:index.php?p=logincp");
}